package com.indeep.user;

public class ResponseEntity<T> {
    private int code;
    private T data;
    private String msg;
    
    // 私有构造函数，防止外部直接使用
    private ResponseEntity(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }
    
    // 成功的构造器，使用默认成功状态码
    public static <T> ResponseEntity<T> success(T data) {
        return new ResponseEntity<T>(200, data, "Success");
    }
    
    // 失败的构造器，不携带自定义状态码
    public static <T> ResponseEntity<T> fallback(String msg) {
        return new ResponseEntity<T>(500, null, msg);
    }
    
    public static <T> ResponseEntity<T> fallback() {
        return new ResponseEntity<T>(500, null, "feign调用异常");
    }
    
    
    // 失败的构造器，携带自定义状态码
    public static <T> ResponseEntity<T> fallback(int code, String msg) {
        return new ResponseEntity<T>(code, null, msg);
    }
    
    // Getters and Setters
    public int getCode() {
        return code;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public T getData() {
        return data;
    }
    
    public void setData(T data) {
        this.data = data;
    }
    
    public String getMsg() {
        return msg;
    }
    
    public void setMsg(String msg) {
        this.msg = msg;
    }
}
